package pacmanreturns;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class GraphicsWindow {
	JFrame frame = new JFrame();
	JButton button = new JButton("test");
	GameCanvas canvas = new GameCanvas();

	public GraphicsWindow(int height, int width) {
		frame.addKeyListener(new KeyHandler());
		frame.add(canvas);

		frame.setSize(height, width);
		frame.setBackground(Color.BLACK);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		frame.setVisible(true);

		Insets margins = frame.getInsets();
		height += margins.left + margins.right;
		width  += margins.top + margins.bottom;
		frame.setSize(height, width);
	}

	public void setTitle(String title) {
		frame.setTitle(title);
	}

	public void repaint() {
		frame.repaint();
	}

	class KeyHandler implements KeyListener {
		public void keyTyped(KeyEvent e) {

		}

		public void keyPressed(KeyEvent e) {
			switch (e.getKeyCode()) {
				case KeyEvent.VK_UP:
					canvas.move(Game.UP);
					break;
				case KeyEvent.VK_DOWN:
					canvas.move(Game.DOWN);
					break;
				case KeyEvent.VK_RIGHT:
					canvas.move(Game.RIGHT);
					break;
				case KeyEvent.VK_LEFT:
					canvas.move(Game.LEFT);
					break;
			}
		}

		public void keyReleased(KeyEvent e) {

		}
	}
}